package com.shaozi.nc.manage.observer;

import java.util.Observable;
import java.util.Observer;

import org.springframework.beans.factory.annotation.Autowired;

import com.shaozi.nc.data.model.CompanyInfoModel;
import com.shaozi.nc.manage.OrgPushMsgManage;
import com.shaozi.nc.manage.PushMsgManage;
import com.shaozi.utils.common.BeanUtils;

/**
 * 监听公司信息变化
 * 
 * @author brenx
 * 
 */
public class AllPushMsgObserver implements Observer {
	
	@Autowired
	private OrgPushMsgManage orgPushMsgMgr;
	@Autowired
	private PushMsgManage pushMsgMgr;

	public AllPushMsgObserver() {
		super();
	}

	@Override
	public void update(Observable o, Object arg) {
		if (arg instanceof CompanyInfoModel) {
			CompanyInfoModel model = (CompanyInfoModel) arg;
			updateCompany(model);
		}
	}

	private void updateCompany(CompanyInfoModel model) {
//		OrgPushMsgManage orgMgr = (OrgPushMsgManage) BeanUtils.getBean("orgPushMsgMgr");
//		String compId = model.getCompId();
//		int skip = 0;
//		int limit = 20;
//		// TODO 后面需要加入载全部的机制
//		List<OrgPushMsgModel> models = orgMgr.loadModels(compId, skip, limit);
		orgPushMsgMgr.updateCompany(model);
		
//		PushMsgManage pushMgr = (PushMsgManage) BeanUtils.getBean("pushMsgMgr");
		pushMsgMgr.updateCompany(model);
		
	}
}
